#!/usr/bin/env python
# -*- coding:utf-8 -*-


import xlwt
from mylog import MyLog

class SaveBallData(object):
    def __init__(self, items):
        self.items = items
        self.log = MyLog()
        self.run(self.items)



    def run(self, items):
        filename = 'lottery.xls'
        book = xlwt.Workbook(encoding='utf8')
        sheet = book.add_sheet('ball')
        sheet.write(0, 0, 'order')
        sheet.write(0, 1, 'red1')
        sheet.write(0, 2, 'red2')
        sheet.write(0, 3, 'red3')
        sheet.write(0, 4, 'red4')
        sheet.write(0, 5, 'red5')
        sheet.write(0, 6, 'red6')
        sheet.write(0, 7, 'blue')

        i = 1
        for item in items:
            sheet.write(i, 0, item.order)
            sheet.write(i, 1, item.red1)
            sheet.write(i, 2, item.red2)
            sheet.write(i, 3, item.red3)
            sheet.write(i, 4, item.red4)
            sheet.write(i, 5, item.red5)
            sheet.write(i, 6, item.red6)
            sheet.write(i, 7, item.blue)
            i = i + 1

        self.log.info('Write To Excel Success')
        book.save(filename)
